package com.jsits.v2x.hurys.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.List;

/**
 * 车辆检测数据Dto
 */
@Data
public class DetectVehicleDto {
    @JsonProperty(value = "DeviceNo")
    private String deviceNo;
    @JsonProperty(value = "Timestamp")
    private String timestamp;

    @JsonProperty(value = "Obj_List")
    private List<DetectVehicleListDto> objList;
    @JsonProperty(value = "Maxspeed_List")
    private List<DetectVehicleListDto> MaxSpeedList;

    public Integer getSpeed() {
        if(objList != null && !objList.isEmpty()) {
            for (DetectVehicleListDto detectVehicleListDto:objList) {
                if(detectVehicleListDto.getXSpeed() < 0) {
                    return detectVehicleListDto.getSpeed();
                }
            }
        }
        if(MaxSpeedList != null && !MaxSpeedList.isEmpty()) {
            for (DetectVehicleListDto detectVehicleListDto:MaxSpeedList) {
                if(detectVehicleListDto.getXSpeed() < 0) {
                    return detectVehicleListDto.getSpeed();
                }
            }
        }
        return 0;
    }

    public String conventMaxSpeedList() {
        String result = "";

        if(objList != null && !objList.isEmpty()) {
            for (DetectVehicleListDto temp : objList) {
                result += " ID : " + temp.getID();
                result += " length : " + temp.getLength();
                result += " xPos : " + temp.getXPos();
                result += " xSpeed : " + temp.getXSpeed();
                result += " yPos : " + temp.getYPos();
                result += " ySpeed : " + temp.getYSpeed();
            }
        } else if(MaxSpeedList != null && !MaxSpeedList.isEmpty()) {
            for (DetectVehicleListDto temp : objList) {
                result += " ID : " + temp.getID();
                result += " length : " + temp.getLength();
                result += " xPos : " + temp.getXPos();
                result += " xSpeed : " + temp.getXSpeed();
                result += " yPos : " + temp.getYPos();
                result += " ySpeed : " + temp.getYSpeed();
            }
        }
        return result;
    }
}
